package json;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONArrayTest {

	/**
	 * @param args
	 * @throws JSONException 
	 */
	public static void main(String[] args) throws JSONException {
		JSONArray jsonarray = new JSONArray("[{'name':'zhaohui','age':24},{'name':'zh','age':15}]");  
        for(int i=0;i<jsonarray.length();i++){  
            String name = jsonarray.getJSONObject(i).getString("name");  
            int age = jsonarray.getJSONObject(i).getInt("age");  
            System.out.println("name="+name);  
            System.out.println("age="+age);  
        }  

        
        String str = "{'name':'zhaohui','age':20,'book':['book1','book2']}";  
        JSONObject obj = new JSONObject(str);  
        System.out.println(obj.getJSONArray("book").getString(0));  
	}

}
